package com.ruoyi.web.controller.buy;

import com.ruoyi.buy.domain.entity.PO.BuyPurchasePost;
import com.ruoyi.buy.domain.entity.buy0003.Buy0003AddInvAndItem;
import com.ruoyi.buy.domain.entity.buy0003.Buy0003AddPostAndItem;
import com.ruoyi.buy.service.IBuyPurchaseBillService;
import com.ruoyi.buy.service.IBuyPurchasePostService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 采购邮寄Controller
 * 
 * @author ruoyi
 * @date 2023-12-07
 */
@RestController
@RequestMapping("/buy0003/post")
public class BuyPurchasePostController extends BaseController
{
    @Autowired
    private IBuyPurchasePostService buyPurchasePostService;

    @Autowired
    private IBuyPurchaseBillService iBuyPurchaseBillService;

    /**
     * 查询采购邮寄列表
     */
    @GetMapping("/list")
    public TableDataInfo list(BuyPurchasePost buyPurchasePost)
    {
        startPage();
        List<BuyPurchasePost> list = buyPurchasePostService.selectBuyPurchasePostList(buyPurchasePost);
        return getDataTable(list);
    }

    /**
     * 导出采购邮寄列表
     */
    @Log(title = "采购邮寄", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BuyPurchasePost buyPurchasePost)
    {
        List<BuyPurchasePost> list = buyPurchasePostService.selectBuyPurchasePostList(buyPurchasePost);
        ExcelUtil<BuyPurchasePost> util = new ExcelUtil<BuyPurchasePost>(BuyPurchasePost.class);
        util.exportExcel(response, list, "采购邮寄数据");
    }

    /**
     * 获取采购邮寄详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(buyPurchasePostService.selectBuyPurchasePostById(id));
    }

    /**
     * 新增采购邮寄
     */
    @Log(title = "采购邮寄", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BuyPurchasePost buyPurchasePost)
    {
        return toAjax(buyPurchasePostService.insertBuyPurchasePost(buyPurchasePost));
    }

    /**
     * 修改采购邮寄
     */
    @Log(title = "采购邮寄", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BuyPurchasePost buyPurchasePost)
    {
        return toAjax(buyPurchasePostService.updateBuyPurchasePost(buyPurchasePost));
    }

    /**
     * 删除采购邮寄
     */
    @Log(title = "采购邮寄", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(buyPurchasePostService.deleteBuyPurchasePostByIds(ids));
    }

    @PostMapping("/viewItem")
    public AjaxResult viewItem(@RequestBody BuyPurchasePost buyPurchasePost)
    {
        return success(iBuyPurchaseBillService.getPostItem(buyPurchasePost));
    }

    /**
     * 新增采购邮寄
     */
    @Log(title = "采购邮寄", businessType = BusinessType.INSERT)
    @PostMapping("/addPostWithDetail")
    public AjaxResult addPostWithDetail(@RequestBody Buy0003AddPostAndItem para)
    {
        return toAjax(buyPurchasePostService.savePostWithItem(para));
    }

    /**
     * 新增采购邮寄
     */
    @Log(title = "采购邮寄", businessType = BusinessType.INSERT)
    @PostMapping("/addInvWithDetail")
    public AjaxResult addInvWithDetail(@RequestBody Buy0003AddInvAndItem para)
    {
        return toAjax(buyPurchasePostService.saveInvWithItem(para));
    }
}
